﻿import com.gamemeal.physics.IForce;
import com.gamemeal.physics.Particle;

/**
 * @author Colin Leung
 */
class com.gamemeal.physics.BoundForce implements IForce {
	private var minx:Number,miny:Number,minz:Number,maxx:Number,maxy:Number,maxz:Number;
	public function BoundForce(a,b,c,d,e,f){
		minx = a;
		miny = b;
		minz = c;
		maxx = d;
		maxy = e;
		maxz = f;
		//catch error, if boundforce setting is undefined.
	}
	
	public function apply(p : Particle, t : Number) {
		if(p.d.x>maxx-p.r){
			p.d.x = maxx-p.r;
			p.vi.x *= -1;
		}else if(p.d.x<minx+p.r){
			p.d.x = minx+p.r;
			p.vi.x *= -1;
		};
		if(p.d.y>maxy-p.r){
			p.d.y = maxy-p.r;
			p.vi.y *= -1;
		}else if(p.d.y<miny+p.r){
			p.d.y = miny+p.r;
			p.vi.y *= -1;
		};
		if(p.d.z>maxz-p.r){
			p.d.z = maxz-p.r;
			p.vi.z *= -1;
		}else if(p.d.z<minz+p.r){
			p.d.z = minz+p.r;
			p.vi.z *= -1;
		};
	}

}